import axios from 'axios'

// 登录请求方法
const loginreq = (method, url, params) => {
  return axios({
    method,
    url,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    params,
    traditional: true,
    transformRequest: [
      function (params) {
        let ret = ''
        for (const it in params) {
          ret +=
              encodeURIComponent(it) +
              '=' +
              encodeURIComponent(params[it]) +
              '&'
        }
        return ret
      }
    ]
  }).then(res => res.data)
}
// 通用公用方法
const req = (method, url, params) => {
  return axios({
    method,
    url,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
      // token: localStorage.getItem('logintoken')
    },
    data: params,
    traditional: true
  }).then(res => res.data)
}
// get方法
const reqget = (method, url, params) => {
  return axios({
    method,
    url,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
      // token: localStorage.getItem('logintoken')
    },
    params,
    traditional: true,
    transformRequest: [
      function (params) {
        let ret = ''
        for (const it in params) {
          ret +=
              encodeURIComponent(it) +
              '=' +
              encodeURIComponent(params[it]) +
              '&'
        }
        return ret
      }
    ]
  }).then(res => res.data)
}
export {
  loginreq,
  reqget,
  req
}
